package test.visualtests;

import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

import table.MultiLineTable;
import table.model.ColumnGroup;
import table.model.ComplexColumn;
import table.model.SimpleColumn;
import table.view.multirowheader.GroupableTableColumnModel;

public class SwapColumns extends JFrame {
	SwapColumns()
	{
		setTitle("Test Swap Columns");
		DefaultTableModel dm = new DefaultTableModel();
        dm.setDataVector(new Object[][]{
            { "119"  , "Finbar" , "John"  , "Saunders" , "ja"     , "ko", "zh","row0"},
            { "911"  , "Roger"  , "Peter" , "Melly"    , "en"     , "fr", "pt","row1"}},
new Object[]{ "SNo." , "First"  , "1"     , "2"        , "Native" , "2" , "3","last"});
        
        GroupableTableColumnModel cm = new GroupableTableColumnModel();
        
        //for(int i=0;i<dm.getColumnCount();i++)
        //{
        SimpleColumn Column0 = new SimpleColumn(0,dm.getColumnName(0));
        SimpleColumn Column1 = new SimpleColumn(1,dm.getColumnName(1));
        SimpleColumn Column2 = new SimpleColumn(2,dm.getColumnName(2));
        SimpleColumn Column3 = new SimpleColumn(3,dm.getColumnName(3));
        SimpleColumn Column4 = new SimpleColumn(4,dm.getColumnName(4));
        SimpleColumn Column5 = new SimpleColumn(5,dm.getColumnName(5));
        SimpleColumn Column6 = new SimpleColumn(6,dm.getColumnName(6));
        SimpleColumn Column7 = new SimpleColumn(7,dm.getColumnName(7));
        
        ComplexColumn complex = new ComplexColumn();
        complex.add(Column3);
        complex.add(Column4);
        
        ComplexColumn complex2 = new ComplexColumn();
        complex2.add(Column6);
        complex2.add(Column7);

        cm.addColumn(Column0);
        cm.addColumn(Column1);
        cm.addColumn(Column2);
        cm.addColumn(complex);
        cm.addColumn(Column5);
        cm.addColumn(complex2);
        //}
        
        // Setup Column Groups
        ColumnGroup name = new ColumnGroup("Name");
        
        ColumnGroup group = new ColumnGroup("Group");
        group.add(Column1);
        group.add(Column2);
        
        name.add(group);
        name.add(complex);
        
        cm.addColumnGroup(name);
        cm.swapColumns(2,4);
        
        MultiLineTable table = new MultiLineTable(dm,cm);
        
        getContentPane().add( table );
        setSize( 800, 600 );
        
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);		
	}
	
	public static void main(String[] args) {
		new SwapColumns();
	}

}
